{include file='public/header' /}

<body>

<div class="x-nav">

  <span class="layui-breadcrumb">

      <a href="">首页</a>

      <a href="">用户管理</a>

      <a><cite>用户列表</cite></a>

  </span>

  <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">

      <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>

  </a>

</div>





<div class="x-body">



    <table class="layui-hide" id="test" lay-filter="test"></table>

    <input id="currid" type="hidden" name="curr" value="1">

   

</div>





<script type="text/html" id="toolbarDemo">

      <div class="layui-form-item"> 
        
        <form class="layui-form" action="" lay-filter="search">

          <div class="layui-input-inline">

                  <select name="is_staff">
                      <option value="">全部用户</option>

                      <option value="1">普通用户</option>

                      <option value="2">公司员工</option>

                  </select>

          </div>

         <input type="text"  placeholder="请输入微信昵称、备注查找" autocomplete="off" class="layui-btn layui-btn-primary" name="name">

          <div class="layui-inline">
            <button class="layui-btn"  lay-event="searchBarFunc"><i class="layui-icon">&#xe615;</i></button>
          </div>

        </form>
      </div>
</script>


<script type="text/html" id="barDemo">

  <div class="layui-btn-group">

      {if $qxarr['shenhe']}
      {{#  if(d.is_staff == 1){ }}
      <button type="button" class="layui-btn" lay-event="edit">上传个人章</button>
      {{#  } }}
      {/if}
     
  </div>




</script>



<script type="text/html" id="switchTp">

      <input type="checkbox" name="员工" value="{{d.id}}" lay-skin="switch" lay-text="员工|用户" lay-filter="sxjFunc" {{ d.is_staff == 1 ? 'checked' : '' }}>

</script>


<script id="imgTp" type="text/html">

    <img  src="{{d.img}}" width="auto" height="50px">

</script>



<script type="text/html" id="is_staff">

    {{#  if(d.is_staff == 1){ }}

         <span class="layui-btn  layui-btn-xs">公司员工</span>

    {{#  } }}


    {{#  if(d.is_staff == 0){ }}

       微信用户

    {{#  } }}

</script>




<style type="text/css">

  /*{# 设置table每一行的height #}*/

  .layui-table-cell {

   height: 50px;

   line-height: 50px;

  }

 </style>





<script>

layui.use('table', function(){

  var table = layui.table

  ,form = layui.form;

  //第一个实例

  table.render({

    elem: '#test'

    ,height:'full-100'

    ,title:'用户列表'

    ,url: "{:url('gList')}" //数据接口
    ,page: true //开启分页

    ,limit:30

    ,toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板

    ,cols: [[ //表头
      {field: 'img', title: '微信头像', templet: '#imgTp'}

      ,{field: 'name', title: '微信昵称'}

      ,{field: 'remark', title: '用户备注',edit:'text'}

      ,{field: 'is_staff', title: '用户身份', templet: '#is_staff'}

      ,{field: 'is_staff',  title: '用户/员工', templet: '#switchTp',sort: true, unresize: true}

      ,{field: 'create_time',  title: '注册时间'}

      ,{fixed: 'right', title:'操作', toolbar: '#barDemo'}
    ]]
     ,done: function(res, curr, count){
      
      $('#currid').val(curr);
      //得到当前页码
      console.log(curr); 
    
  }

  });




 //头工具栏事件

  table.on('toolbar(test)', function(obj){

      if(obj.event === 'searchBarFunc'){

              var data = form.val('search');
            
              table.reload('test',{
                  url: "{:url('gList')}",

                  page: {
                    curr: 1 //重新从第 1 页开始
                  }

                 ,where: data
                 ,done: function(res, curr, count){
                    form.val('search', data);
                    $('#currid').val(curr);

                 }
              })


        }

  });




 //监听上下架操作

  form.on('switch(sxjFunc)', function(obj){

    var is_xj = obj.elem.checked?1:0;

    var is_xj_str = obj.elem.checked?'员工':'用户';

    var curr = $('#currid').val();


    $.post("{:url('editSxj')}",{id:this.value,is_xj:is_xj},function (res) {
        
            if (res == 1) {

                var data = form.val('search');
              
                table.reload('test',{
                    url: "{:url('gList')}",

                    page: {
                      curr: curr 
                    }

                   ,where: data
                   ,done: function(res, curr, count){
                      form.val('search', data);
                      $('#currid').val(curr);

                   }
                })

                layer.msg('成功设置为'+is_xj_str,{icon:1,time:2000});
                // layer.tips(is_xj_str, obj.othis);
            }else{

                if (is_xj == 1) {
                    obj.elem.checked = false;
                }else{
                    obj.elem.checked = true;
                }
                layer.tips('暂无权限', obj.othis);
                form.render('checkbox')
            }
                

    })

  });




  //监听单元格编辑
  table.on('edit(test)', function(obj){

    var value = obj.value //得到修改后的值

    ,data = obj.data //得到所在行所有键值

    ,field = obj.field; //得到字段

    if(field=='remark'){

        var old=$(this).prev().text();

        var curr = $('#currid').val();

        $.post("{:url('editpx')}",{id:data.id,remark:value},function (res) {
      
                if(res == 1){

                    var data = form.val('search');
                  
                    table.reload('test',{
                        url: "{:url('gList')}",

                        page: {
                          curr: curr 
                        }

                       ,where: data
                       ,done: function(res, curr, count){
                          form.val('search', data);

                       }
                    })

                    layer.msg('更改成功', {icon: 1});

                }else {
  
                      var data = form.val('search');
                    
                      table.reload('test',{
                          url: "{:url('gList')}",

                          page: {
                            curr: curr 
                          }

                         ,where: data
                         ,done: function(res, curr, count){
                            form.val('search', data);

                         }
                      })

                      layer.msg('暂无权限',{icon:2,time:2000});
                     
                        

                      return;

                }

            })

    }


  });




   //监听行工具事件
  table.on('tool(test)', function(obj){

    var data = obj.data;
    x_admin_show('上传个人章',"{:url('edit')}?id="+data.id,'400','500');

  });



  

});

</script>











</body>

</html>